<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户登录 - {$site_name}</title>
    <link rel="bookmark" href="__ROOT__/favicon.ico"/>
    <tc_include file="Public/common:header"/>
</head>
<body>
<!--header start-->
<tc_include file="Public/common:pc_header"/>
<!--header end-->
<!--body start-->
<div class="pc_body">
    <div class="layui-main">
        <!--login start-->
        <div class="pc_login_box">
            <!--tel login-->
            <div class="pc_tel_text">手机号登录</div>
            <!--tel login-->
            <div>
                <div class="layui-form layui-form-pane" action="">
                    <!--err tip start-->
                    <div class="pc_login_tip"><span class="layui-icon"
                                                    style="color:#f56b3f;margin-top: 5px">&#x1007;</span> <span
                            id="pc_login_tip"></span></div>
                    <!--err tip end-->
                    <div class="layui-form-item">
                        <label class="layui-form-label pc_input_icon">
                            <span class="layui-icon">&#xe63b;</span>
                        </label>

                        <div class="layui-input-block pc_bg_white">
                            <input type="text" name="phone" id="phone" required=""
                                   lay-verify="phone" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label pc_input_icon">
                            <span class="layui-icon">&#xe63c;</span>
                        </label>

                        <div class="layui-input-block pc_bg_white">
                            <input type="text" name="code" id="code" required="" lay-verify="number"
                                   placeholder="请输入验证码" autocomplete="off" class="layui-input">
                            <span class="pc_get_code" id="pc_get_code">发送验证码</span>
                        </div>
                        <input type="hidden" name="r" id="r" value="{:session('TOKEN')}">
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-danger" lay-submit lay-filter="*" style="width: 100%">登录
                        </button>
                    </div>

                </div>
            </div>
        </div>
        <!--login end-->

    </div>

</div>
<!--body end-->
<!--footer start-->
<tc_include file="Public/common:pc_footer"/>
<!--footer end-->
<script src="__PUBLIC__/tools/layui/layui.js"></script>
<script>
    layui.config({
        base: '__PUBLIC__/tools/layui/model/'
    }).extend({
        base: 'base'
    });
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'util', 'jquery', 'base'], function () {
        var layer = layui.layer, form = layui.form(), util = layui.util, base = layui.base, $ = layui.jquery;
        //fixbar
        util.fixbar();
        //form
        form.on('submit(*)', function (data) {
            var index = null;
            $.ajax({
                url: '{:U("/Api/Pc/user_login/")}',
                type: 'post',
                data: data.field,
                dataType: 'json',
                beforeSend: function () {
                    index = layer.load(0, {shade: false});
                },
                success: function (ret) {
                    layer.close(index);
                    console.log(JSON.stringify(ret));
                    switch (ret.retCode) {
                        case 200:
                            window.location.href = "{:U('Portal/Index/user_center')}";
                            break;
                        //验证码失效
                        case 401:
                            $(".pc_login_tip").show();
                            $("#pc_login_tip").text(ret.retDesc);
                            $("#code").val("");
                            break;
                        case 402:
                            $(".pc_login_tip").show();
                            $("#pc_login_tip").text(ret.retDesc);
                            $("#code").val("");
                            break;
                        default :
                            $(".pc_login_tip").show();
                            $("#pc_login_tip").text(ret.retDesc);

                            break;
                    }
                }
            });

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //pc_tel_code
        $("#pc_get_code").click(function () {
            //获取验证码
            var status = base.get_code($("#phone").val(), $("#r").val(), '{:U("/Api/Pc/get_tel_code/phone/")}/', this);
            if (!status) {
                $(".pc_login_tip").show();
                $("#pc_login_tip").text("抱歉，手机号格式错误！");
                $("#phone").focus();
            } else {

            }
        });

        //code
        //base.get_code()

    });
</script>

</body>
</html>